package com.redisdemo.demo.redisMq.test;


import com.redisdemo.demo.redisMq.util.RedisClientUtil;
import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisStreamCommands;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yvwc
 * @since 2019-09-21
 */
@RestController
@RequestMapping("/x")
public class RedisController {

    @Autowired
    RedisClientUtil redisClientUtil;

    @Value("${spring.redis.host}")
    private  String host;
    @Value("${spring.redis.password}")
    private  String password;
    @Value("${spring.redis.port}")
    private  int port;

    @GetMapping(value = "/getRedis")
    public String getProductList(){
//        RedisClient redisClient = redisClientUtil.getRedisClient();
        RedisURI redisUri = RedisURI.Builder.redis("127.0.0.1")
                .withPort(6379)
                .withPassword("")
                .withDatabase(0)
                .build();
        RedisClient redisClient = RedisClient.create(redisUri);
        StatefulRedisConnection<String, String> connection = redisClient.connect();
        RedisStreamCommands<String, String> streamCommands = connection.sync();
        String ret="长度：" + streamCommands.xlen("first-stream");
        connection.close();
        redisClient.shutdown();
        return ret;
    }

}
